home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 June / macformat-038.iso / Shareware in MacFormat / Creator Changer 2.5 / Code & Resource / Creator Changer.menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-15  |  4.3 KB  |  138 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  *    This file handles all of the pop-up menu options.  It updates the
  3.  *    menu when needed, and decides what parts were clicked on.
  4.  **********************************************************************/
  5.  
  6. #include "Creator Changer.h"
  7. #include "Creator Changer.menu.h"
  8.  
  9.  
  10. /**********************************************************************
  11.  *    Function Handle_pop_up_menu(), this function handles the events
  12.  *    given to the prefered types pop-up menu.
  13.  **********************************************************************/
  14.  
  15. void Handle_pt_Pop_Up_Menu(Handle menu_handle, DialogPtr the_dialog, int creator, int file, int description)
  16.     {
  17.     
  18.     Str32        description_type;
  19.     Str4        creator_type, file_type;
  20.     short        item_type, the_choice;
  21.     Handle        creator_handle, file_handle, desc_handle;
  22.     pref_types    **rsrc_handle;
  23.     Rect        creator_rect, file_rect;
  24.     
  25.     the_choice=GetCtlValue((ControlHandle)menu_handle);
  26.     if(the_choice)
  27.         {
  28.         UseResFile(CreatorChangerPref);
  29.             rsrc_handle=(pref_types **)GetResource(PREF_PT, The_pt_Type[the_choice]);
  30.             if(description) p_Str_Copy((**rsrc_handle).Description, description_type);
  31.             p_Str_Copy((**rsrc_handle).CreatorType, creator_type);
  32.             p_Str_Copy((**rsrc_handle).FileType, file_type);
  33.         UseResFile(CreatorChangerApp);
  34.         
  35.         if(description)
  36.             {
  37.             GetDItem(the_dialog, description, &item_type, &desc_handle, &file_rect);
  38.             SetIText(desc_handle, description_type);
  39.             }
  40.         
  41.         GetDItem(the_dialog, creator, &item_type, &creator_handle, &creator_rect);
  42.         SetIText(creator_handle, creator_type);
  43.     
  44.         GetDItem(the_dialog, file, &item_type, &file_handle, &file_rect);
  45.         SetIText(file_handle, file_type);
  46.         ReleaseResource((Handle)rsrc_handle);
  47.         }
  48.     (**(ControlHandle)menu_handle).contrlValue=0;
  49.     if(!description) Draw1Control((ControlHandle)menu_handle);
  50.     PT_Item_To_Edit=the_choice;
  51.         
  52.     }
  53.  
  54.  
  55.  
  56. /**********************************************************************
  57.  *    Function Make_Pop_Up_Menu(), this function makes the pop-up menu
  58.  *    for the prefered types menu.
  59.  **********************************************************************/
  60.  
  61. void Make_Pop_Up_Menu(short ID, OSType the_type, short num)
  62.     {
  63.     
  64.     short        item;
  65.     pref_types    **rsrc_handle_pt;
  66.     auto_chng    **rsrc_handle_ac;
  67.     MenuHandle    menu_handle;
  68.     
  69.     menu_handle=GetMenu(ID);
  70.     DisposeMenu(menu_handle);
  71.     
  72.     menu_handle=GetMenu(ID);
  73.     UseResFile(CreatorChangerPref);
  74.         for(item=0;item<num;item++)
  75.             {
  76.             if(the_type==PREF_PT)
  77.                 {
  78.                 The_pt_Type[item+1]=item+Strt_Rsrc;
  79.                 rsrc_handle_pt=(pref_types **)GetResource(the_type, item+128);
  80.                 InsMenuItem(menu_handle, (**rsrc_handle_pt).Description, item);
  81.                 ReleaseResource((Handle)rsrc_handle_pt);
  82.                 }
  83.             else if(the_type==PREF_AC)
  84.                 {
  85.                 The_ac_Type[item+1]=item+Strt_Rsrc;
  86.                 rsrc_handle_ac=(auto_chng **)GetResource(PREF_AC, item+128);
  87.                 InsMenuItem(menu_handle, (**rsrc_handle_ac).Name, item);
  88.                 ReleaseResource((Handle)rsrc_handle_ac);
  89.                 }
  90.             }
  91.     UseResFile(CreatorChangerApp);
  92.     
  93.     }
  94.  
  95.  
  96.  
  97. /**********************************************************************
  98.  *    Function Handle_ac_Pop_Up_Menu(), this function handles the events
  99.  *    given to the auto change pop-up menu.
  100.  **********************************************************************/
  101.  
  102. void Handle_ac_Pop_Up_Menu(Handle menu_handle, DialogPtr the_dialog, int from_file_id, int to_creator_id, int to_file_id)
  103.     {
  104.     
  105.     Str16        name;
  106.     Str4        from_file, to_creator, to_file;
  107.     short        the_type, the_choice;
  108.     Handle        the_handle;
  109.     Rect        the_rect;
  110.     auto_chng    **rsrc_handle;
  111.     
  112.     the_choice=GetCtlValue((ControlHandle)menu_handle);
  113.     if(the_choice)
  114.         {
  115.         UseResFile(CreatorChangerPref);
  116.             rsrc_handle=(auto_chng **)GetResource(PREF_AC, The_ac_Type[the_choice]);
  117.             
  118.             p_Str_Copy((**rsrc_handle).FromFile,  from_file);
  119.             p_Str_Copy((**rsrc_handle).ToCreator, to_creator);
  120.             p_Str_Copy((**rsrc_handle).ToFile,       to_file);
  121.         UseResFile(CreatorChangerApp);
  122.         
  123.         GetDItem(the_dialog, from_file_id, &the_type, &the_handle, &the_rect);
  124.         SetIText(the_handle, from_file);
  125.         
  126.         GetDItem(the_dialog, to_creator_id, &the_type, &the_handle, &the_rect);
  127.         SetIText(the_handle, to_creator);
  128.     
  129.         GetDItem(the_dialog, to_file_id, &the_type, &the_handle, &the_rect);
  130.         SetIText(the_handle, to_file);
  131.         
  132.         ReleaseResource((Handle)rsrc_handle);
  133.         }
  134.     (**(ControlHandle)menu_handle).contrlValue=0;
  135.     Draw1Control((ControlHandle)menu_handle);
  136.     AC_Item_To_Edit=the_choice;
  137.         
  138.     }